package com.macro.sms.controller;

import com.macro.sms.service.SmsService;
import com.macro.sms.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ：小海
 * @dete ：2021-03-26 08:23:43
 * @Describe : 手机短信接口
 */
@Api(tags = "手机短信接口")
@RestController
public class SmsController {

    @Autowired
    private SmsService smsService;

    @ApiOperation(value = "获取手机短信")
    @GetMapping("/getCode/{phone}")
    public Result getPhoneCode(@ApiParam(name = "phone",value = "手机号",required = true)@PathVariable String phone){

        if (StringUtils.isEmpty(phone)){
            return Result.error().message("手机号不能为空");
        }
        int i = smsService.getPhoneCode(phone);
        if ( i == 0){
            return Result.error().message("短信发送失败");
        }

        return Result.ok().message("短信已发送");
    }
}
